<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}

if($_POST['sub']!=''){

    $id=empty($_POST['id'])?0:(int)$_POST['id'];
	unset($_POST['id']);
	unset($_POST['sub']);
	$data=array('title'=>$_POST['title'],
    "icon"=>trim($_POST["attachment_fileName"]),
    "point"=>trim($_POST["point"]),
    "disabled"=>intval($_POST["disabled"])   
    );
    if(trim($_POST['title'])==""){
        jumpajax('300','等级名称不能为空','');
    }

   
 	if($id==0){
	    $id=$ezhand->insert("usergroup",$data);

        $levellistrow=$ezhand->select_all('usergroup','*','1=1');
        $levellist=array();
        while(list($k,$trow)=each($levellistrow)){
            $typeid=$trow["id"];
            $levellist[$typeid]=$trow;
        }
            
        ez_set_cache("usergroup",$levellist);
		jumpajax('200','保存成功','','closeCurrent');
	}
	else{
	    $ezhand->update("usergroup",$data,'id="'.$id.'"');
        $levellistrow=$ezhand->select_all('usergroup','*','1=1');
        $levellist=array();
        while(list($k,$trow)=each($levellistrow)){
            $typeid=$trow["id"];
            $levellist[$typeid]=$trow;
        }
            
        ez_set_cache("usergroup",$levellist);        
		jumpajax('200','修改成功','','closeCurrent');
	}
}
else{
	$id=empty($_GET['id'])?0:(int)$_GET['id'];
    
    if($id==0){
	    $row=array();
	}
	else{
	    $row=$ezhand->select("usergroup",'*','id="'.$id.'"');
	}
}
?>